using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using B.S.Databasic.Api.Read.Application.Command.Role;
using B.S.Databasic.ErrorCode;
using B.S.Databasic.Domain.RBAC;

namespace B.S.Databasic.Api.Read.Controllers
{
    /// <summary>
    /// 角色相关查询接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class RoleController : ControllerBase
    {
        private readonly IMediator _mediator;
        public RoleController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 分页查询角色及其权限
        /// </summary>
        /// <param name="command">分页参数和筛选条件</param>
        /// <returns>分页角色数据，包含权限名称</returns>
        [HttpGet]
        [Authorize]
        public Task<ApiPageing<RoleDto>> GetRolePage([FromQuery] GetRolePageCommand request)
        {
            var result = _mediator.Send(request);
            return result;
        }
        /// <summary>
        /// 查询所有角色
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回所有权限</returns>
        [HttpGet]
        [Authorize]
        public async Task<ApiResult<List<RoleModel>>> GetRoleAll([FromQuery] GetRoleAllCommand request)
        {
            var result = await _mediator.Send(new GetRoleAllCommand());
            return result;
        }
    }
}